package com.tentative.competition.web.controller.schedule.client;

import com.tentative.competition.common.annotation.Anonymous;
import com.tentative.competition.common.core.domain.AjaxResult;
import com.tentative.competition.common.model.schedule.param.EmailParam;
import com.tentative.competition.schedule.service.CodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther: Smile Huang
 * @date: 2023/6/22 19:03
 * @desc:
 * @version: 2.0
 */
@Api(tags = "client-邮箱验证码")
@RestController
@RequestMapping("/client/code")
public class CodeController {

    @Autowired
    private CodeService codeService;

    @Anonymous
    @ApiOperation("邮箱验证码")
    @PostMapping("/getCode")
    @ResponseBody
    public AjaxResult getCode(@RequestBody EmailParam param){
        codeService.getCode(param.getEmail(),"_code");
        return AjaxResult.success();
    }

    @Anonymous
    @ApiOperation("用户更新的邮箱验证码")
    @PostMapping("/getUpdateUserCode")
    @ResponseBody
    public AjaxResult getUpdateUserCode(@RequestBody EmailParam param){
        codeService.getCode(param.getEmail(),"_user_code");
        return AjaxResult.success();
    }

    @Anonymous
    @ApiOperation("忘记密码验证码")
    @PostMapping("/forgetPassword")
    @ResponseBody
    public AjaxResult forgetPassword(@RequestBody EmailParam param){
        codeService.getForgetPasswordCode(param.getEmail(),"_forget_code");
        return AjaxResult.success();
    }

    @Anonymous
    @ApiOperation("作品提交验证码")
    @GetMapping("/getWorksCode")
    public AjaxResult getWorksCode(){
        codeService.getWorksCode("works_code");
        return AjaxResult.success();
    }
}
